require(['jquery', 'cookie', 'app', 'lay', 'base64'], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                th: {
                    id: "",
                    name: "",
                    content: ""
                }
            }
            , created: function () {
                var jon = playGet("/v3/api/note/essay/get/" + new acquire().parameterMap["id"], "", "").data;
                jon['content'] = Base64.decode(jon['content']);
                jon['image'] = JSON.parse(jon.image);
                this.th = jon;
                setTimeout(function () {
                    editor.txt.html("");
                    editor.txt.html(jon['content']);
                },1500);
            }
            , methods: {
                delNote: function (i) {
                    var re = this.th.image;
                    re.splice(i, 1);
                    this.th.image = re;
                }
            }
        });
        layui.use(['form', 'laydate', 'upload'], function () {
            var upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#upload' //绑定元素
                , url: configPro.server_img_interface //上传接口
                , done: function (res) {
                    if (dic.th.image == null) {
                        var ic  = dic.th
                        ic.image = new Array();
                        ic.image.push(res.data.data.src);
                        dic.th = ic;
                    } else {
                        var ic  = dic.th
                        ic.image.push(res.data.data.src);
                        dic.th = ic;
                    }
                }
                , error: function (res) {
                    alr("上传失败");
                }
                , accept: 'file'
            });
        });
        layui.use('form', function () {
            var form = layui.form;
            form.render();
            form.on('submit(formDemo)', function (data) {
                var jon = data.field;
                var xe = editor.txt.html();
                jon["id"] = dic.th.id;
                jon['content'] = Base64.encode(xe);
                jon['image'] = JSON.stringify(dic.th.image);
                if(jon["isIndex"]==="on"){
                    jon["isIndex"] = true;
                }else{
                    jon["isIndex"] = false
                }
                var re = playPost("/v1/api/essay/save", "", JSON.stringify(jon));
                alr(re['msg']);
                return false;
            });
        })
    });
    require(['wangEditor'], function (E) {
        editor = new E("#xq");
        editor.customConfig.uploadImgServer = configPro.uploadsWang; //上传URL
        editor.customConfig.uploadImgMaxSize = 10 * 1024 * 1024;
        editor.customConfig.uploadImgMaxLength = 5;
        editor.customConfig.uploadFileName = 'myFileName';
        editor.customConfig.uploadImgHooks = {
            customInsert: function (insertImg, result, editor) {
                debugger;
                var url = result.data;
                insertImg(url);
            }
        };
        editor.create();
    });
});